package com.mach.platform.controller;

import com.google.common.collect.Lists;
import com.mach.platform.domain.Response;
import com.mach.platform.service.CarbonServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;

/**
 * @author Administrator
 * @Description: 能耗分析管理 接口
 * @Package: com.mach.platform.controller
 * @time 2019/2/25 0025 15:49
 */
@Api(tags = { "能耗分析管理接口" })
@RestController
@RequestMapping(value = "enManager")
public class EnergyAnalysisCtrl {

    @Autowired
    private CarbonServiceImpl carbonService;

    @ApiOperation(value = "xxx汇总碳排--总碳排,单车碳排,总产量,平均温度", notes = "参数 time 自由传参", produces = "application/json")
    @PostMapping("/allCarList")
    public Response carbonss (@RequestParam Map<String, Object> params,@RequestParam("summaryType") String  summaryType) {
            List<Map> result = Lists.newArrayList();
            Random random = new Random();
            String[] types=null;
            String[] units=null;
            if(summaryType.equals("1")){//汇总成本
                types = new String[] { "总成本", "单车成本", "总产量", "平均温度" };
                units = new String[] {"元", "元/辆", "辆", "℃"};
            }else if(summaryType.equals("2")){//汇总用水
                types = new String[] { "总用水", "单车用水", "总产量", "平均温度" };
                units = new String[] {"t", "t/辆", "辆", "℃"};
            }else if(summaryType.equals("3")){//汇总用电
                types = new String[] { "总用电", "单车用电", "总产量", "平均温度" };
                units = new String[] {"kwh", "kwh/辆", "辆", "℃"};
            }else if(summaryType.equals("4")){//汇总燃气
                types = new String[] { "总燃气", "单车燃气", "总产量", "平均温度" };
                units = new String[] {"Nm³", "Nm³/辆", "辆", "℃"};
            }else if(summaryType.equals("5")){//汇总冷量
                types = new String[] { "总冷量", "单车冷量", "总产量", "平均温度" };
                units = new String[] {"Kcal", "Kcal/辆", "辆", "℃"};
            }else if(summaryType.equals("6")){//汇总蒸汽
                 types = new String[] { "总蒸汽", "单车蒸汽", "总产量", "平均温度" };
                 units = new String[] {"t", "t/辆", "辆", "℃"};
            }else if(summaryType.equals("7")){//汇总空气
                types = new String[] { "总空气", "单车空气", "总产量", "平均温度" };
                units = new String[] {"m³", "m³/辆", "辆", "℃"};
            }
            Map curMap1 = new HashMap(4);
            int one = random.nextInt(15300) + 1789333;
            int one2 = random.nextInt(15300) + 1789333;
            curMap1.put("type", types[0]);
            curMap1.put("useNum", one);
            curMap1.put("unit", units[0]);
            int iu3 = random.nextInt(15) % 2;
            int iu4 = random.nextInt(15) % 2;
            curMap1.put("lastPeriod", ( iu3 == 0 ? "+" : "-" ) + random.nextInt(90) + "%");
            curMap1.put("kpi", ( iu4 == 0 ? "+" : "-" ) + random.nextInt(80) + "%");

            int production = random.nextInt(15300) + 20000;
            Map curMap3 = new HashMap(4);
            curMap3.put("type", types[2]);
            curMap3.put("unit", units[2]);
            curMap3.put("useNum", production);

            Map curMap2 = new HashMap(4);
            curMap2.put("type", types[1]);
            curMap2.put("unit", units[1]);
            curMap2.put("useNum", new BigDecimal(one).divide(new BigDecimal(production), 2, RoundingMode.HALF_UP)
                    .setScale(2, RoundingMode.HALF_UP));
            int iu = random.nextInt(15) % 2;
            curMap2.put("lastPeriod", ( iu == 0 ? "+" : "-" ) + random.nextInt(90) + "%");
            int iu2 = random.nextInt(15) % 2;
            curMap2.put("kpi", ( iu2 == 0 ? "+" : "-" ) + ( random.nextInt(80) + 17 ) + "%");

            double temp = random.nextInt(5) + 18 + random.nextDouble();
            Map curMap4 = new HashMap(4);
            curMap4.put("type", types[3]);
            curMap4.put("unit", units[3]);
            curMap4.put("useNum", new BigDecimal(temp).setScale(2, RoundingMode.HALF_UP));

            result.add(curMap1);
            result.add(curMap2);
            result.add(curMap3);
            result.add(curMap4);

            return Response.ok(result);
    }
}
